<?php
namespace app\admin\model\admin;


use app\admin\model\Base;
use think\facade\Request;

class Admin extends Base
{
    protected $insert=['register'];
    protected $validate=true;
    protected $hidden=['admin_password'];
    public function setAdminPasswordAttr($value){
        return password_hash($value,PASSWORD_DEFAULT);
    }
    public function setStatusAttr($value){
        if(is_null($value)){
            $value=1;
        }
        return $value;
    }

    public function checkPassword($password){
        return password_verify($password,$this->getAttr('admin_password'));
    }

    public function addLog(){
        $ip=Request::ip();
        $login_time=Request::time();
        $this->save(['admin_last_ip'=>$ip,'login_time'=>$login_time]);
    }
    public function setRegisterAttr(){
        return time();
    }
}